axios.interceptors.request.use(req=>{
    req.headers.accesstoken=localStorage.getItem("accessToken");
    return req;
})
axios.interceptors.response.use(resp=>{
    if (resp.headers.accesstoken!=null){
        localStorage.setItem("accessToken",resp.headers.accesstoken)
    }
    return resp;
})


new Vue({
    el:"#app",
    data:{
        account:{
            oldPassword:"",
            newPassword:"",
        },
        account1:{
            accountNickName:""
        },
        updatePasswordWindow: false,
        updateNickNameWindow: false,
        myUser:{}
    },
    methods: {
        handleCommand(comment) {
            if (comment == 1) {
                this.updateNickNameWindow = true
            } else if (comment == 2) {
                this.updatePasswordWindow = true
            }  else if (comment == 3) {
                this.out()
                localStorage.removeItem("accessToken")
            }
        },
        updatePassword(){
            axios.post("/account/updatePassword",this.account).then(resp=>{
                alert(resp.data.message)
              if(resp.data.code==200){
                  location.href="/page/adminLogin.html"
              }else{
                  this.account.newPassword=""
                  this.account.oldPassword=""
                  this.updatePasswordWindow=false
              }
            })
        },
        updateNickName(){
            axios.post("/account/updateNickname",this.account1).then(resp=>{
                alert(resp.data.message)
                this.updateNickNameWindow=false
                location.reload()
            })
        },
        out(){
            axios.post("/account/outLogin").then(resp=>{
                if(resp.data.code==200){
                    location.href="/page/adminLogin.html";
                }
            })
        },
        handleClose(){
            this.updateNickNameWindow=false;
            this.updatePasswordWindow=false;
        },
        loadUser(){
            let user=JSON.parse(localStorage.getItem("user"))
            this.myUser=user
            console.log(this.myUser)
        }
    },
    created(){
        this.loadUser()
    }
})
